package com.ruoyi.sysem.exception;


import com.ruoyi.sysem.util.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;

@RestControllerAdvice//AOP
//AOP 前置 后置 环绕  返回  异常
public class ProductExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("调用了公共异常处理类");
        return new Result(false,"0000",e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Result runtime(Exception e){
        e.printStackTrace();
        System.out.println("调用了RuntimeException公共异常处理类");
        return new Result(false,"0001",
                e.getClass().getName() +"==>" + e.getMessage());
    }

    @ExceptionHandler(SQLException.class)
    @ResponseBody
    public Result sql(Exception e){
        e.printStackTrace();
        System.out.println("调用了SQLException公共异常处理类");
        return new Result(false,"0002",e.getMessage());
    }

}
